import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/file/file';


export interface FileParam {
    platformType?: string;
    bizId?: string;
    bizType?: string;
    dataType?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface FileResponse {
    id?: number;
    platformType?: number;
    bizId?: number;
    bizType?: number;
    dataType?: number;
    contentType?: number;
    originalFileName?: string;
    finalFileName?: string;
    relativePath?: string;
    url?: string;
    md5?: string;
    ext?: string;
    size?: string;
    createdYear?: string;
    createdMonth?: string;
    createdDay?: string;

    status?: number;
    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface FileSaveCommand {
    id?: number;
    platformType?: number;
    bizId?: number;
    bizType?: number;
    dataType?: number;
    contentType?: number;
    originalFileName?: string;
    finalFileName?: string;
    relativePath?: string;
    url?: string;
    md5?: string;
    ext?: string;
    size?: string;
    createdYear?: string;
    createdMonth?: string;
    createdDay?: string;
}

export interface FileResponseList {
    list: FileResponse[];
    total: number;
}


// 通过FileParam参数获取分页列表
export function pageFile(params: FileParam) {
    return axios.get<FileResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取文件信息
export function getFile(id: number) {
    return axios.get<FileResponse>(`${BASE_URL}/${id}`);
    
}

export function listFile(params: FileParam) {
    return axios.get<FileResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加文件
export function addFile(params: FileSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新文件
export function updateFile(params: FileSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除文件
export function deleteFile(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}


// 文件上传
export function uploadFile(data: FormData) {
    return axios.post(`${BASE_URL}/upload`, data);
}
  